Type.registerNamespace("BM");

// CustomConstraint object

BM.CustomConstraint = function(leafItem, data) {
    BM.CustomConstraint.initializeBase(this, [leafItem, data]);
}

BM.CustomConstraint.prototype = {

    getFunctionName: function() {
        ///	<summary>
        ///	returns the name of the function to validate against
        ///	</summary>
        ///	<returns type="String" /> 
        return this.getProperty('name');
    },

    validatesAgainstFunction: function() {
        if (this.getFunctionName() == null) return true;
        try {
            var func = eval(this.getFunctionName());
            return func(this.getValue(), this.item.getId());            
        } catch (e) {
            alert('Invalid function:' + this.getFunctionName());
            return true;
        }
    },

    isMet: function() {
        return this.validatesAgainstFunction();
    },

    getDefaultErrorText: function() {
        return BM.Messages['CustomConstraintError'] + " " + this.getFunctionName();
    }
}

BM.CustomConstraint.registerClass("BM.CustomConstraint", BM.Constraint);